<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>修改密码</title>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../css/own.css"/>
    <link rel="stylesheet" type="text/css" href="../css/iconfont.css"/>
    
    <style type="text/css">.mui-input-row label {
	width: 20%;
}

.mui-input-row label~input {
	width: 80%;
}</style>
</head>
<body>
	
	<header class="mui-bar mui-bar-nav own-header-hidden">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<h1 class="mui-title">修改密码</h1>
	</header>
	
	<div class="mui-content own-content-padding">
		<div class="mui-card" style="margin-top: 30px;">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label><span class="mui-icon iconfont icon-jiumima"></span></label>
					<input type="password" class="mui-input-clear" placeholder="旧密码" />
				</div>
				<div class="mui-input-row">
					<label><span class="mui-icon iconfont icon-mimaxiugai"></span></label>
					<input type="password" class="mui-input-clear" placeholder="新密码" />
				</div>
				<div class="mui-input-row">
					<label><span class="mui-icon iconfont icon-queren"></span></label>
					<input type="password" class="mui-input-clear" placeholder="确认新密码" />
				</div>
			</form>
		</div>
		<div class="mui-button-row" style="margin: 10px 15px;">
			<button type="button" class="mui-btn mui-btn-link own-btn-green mui-btn-block" style="padding: 5px 0px;">修改密码</button>
		</div>
	</div>
	
	<script type="text/javascript" src="../js/jquery-1.11.1.min.js" ></script>
	<script src="../js/mui.min.js" charset="UTF-8"></script>
	<script src="../js/own.js" charset="UTF-8"></script>
	<script src="../js/ajax.js" charset="UTF-8"></script>
	<script type="text/javascript" charset="UTF-8">mui.init({
	swipeBack: true
});

var inputList;
var changepwdWebview;
mui.plusReady(function() {
	//选出所有input
	inputList = document.querySelectorAll('input[type="password"]');
	changepwdWebview = plus.webview.currentWebview();

	document.querySelector('button[type="button"]').addEventListener('tap', function() {
		for(var i = 0; i < inputList.length; i++) {
			if(inputList[i].value.length <= 0) {
				var alertMSG;
				if(i == 0) {
					alertMSG = '请输入旧密码';
				} else if(i == 1) {
					alertMSG = '请输入新密码';
				} else if(i == 2) {
					alertMSG = '两次输入密码必须一致';
				}
				mui.toast(alertMSG);
				return;
			}
		}
		if(inputList[1].value != inputList[2].value) {
			mui.toast('两次输入密码必须一致');
			return;
		}

		//开始执行修改密码联网
		//				ajax_change_pwd({
		//					confirm_pwd:inputList[2].value,
		//					new_pwd:inputList[1].value,
		//					old_pwd:inputList[0].value
		//				});
		/*	var data = {};
		data.accountId = plus.storage.getItem("accountId");
		data.oldpassword =   plus.storage.getItem("passWord");
		data.newpassword =inputList;
		data.accountName = 	plus.storage.getItem("user");
		data.tokenCode =   plus.storage.getItem("tokenCode");
		$.ajax({
			url: url+"rest/modifyCheckCode",
			type: "POST",
			data: data,
			success: function(result){
				//返回json字符串，转成json对象进行属性获取
				//{"status":"value","msg":"提示信息"}
				// status 为 0  表示 调用成功，为其他值则为失败
				result = JSON.parse(result);
				$("#resultCode").val(result.status);
				$("#resultMsg").val(result.msg);
				if(result.status != '0'){
					alert(result.msg);
				}else{
					$("#tokenCode").val(result.token);
					//alert(result.token);//token值
				}
			}
		});
*/

	
		

		mui.ajax(url + "rest/modifyCheckCode", {
			data: {
				accountId: plus.storage.getItem("accountId"),
				oldpassword: inputList[0].value,
				newpassword: inputList[1].value,
				accountName: plus.storage.getItem("user"),
				tokenCode: plus.storage.getItem("tokenCode")
			},
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 10000, //超时时间设置为10秒；

			success: function(result) {
				//服务器返回响应，根据响应结果，分析是否登录成功；
				//result = JSON.parse(result);
				$("#resultCode").val(result.status);
				$("#resultMsg").val(result.msg);
				if(result.status != '0') {
					mui.alert(result.msg);
				} else {
					//$("#tokenCode").val(result.token);
					changePwdSuccess();
					//alert(result.token);//token值
				}
			},
			error: function(xhr, type, errorThrown) {
				//异常处理；
				console.log(type);
			}
		});

	}, false);

	//为页面添加事件监听hide
	changepwdWebview.addEventListener('hide', function() {
		//将所有的之前输入过的密码全部清空
		mui.each(inputList, function(index, item) {
			item.value = '';
		});
	}, false);

});

//密码修改返回函数
function changePwdSuccess() {
	//if (data.code == '000000') {
	//成功修改
	//删除本地user信息
	//将页面返回显示修改成功需要从新登陆
	localStorage.removeItem('user');
	mui.toast('修改成功，需要重新登录');
	mui.back();
	//}
}</script>
	
</body>
</html>